package com.sunducation.wts.databinding3

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.databinding.ObservableArrayList
import androidx.databinding.ObservableArrayMap
import com.sunducation.wts.databinding3.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

    private lateinit var user:PlainUser
    private lateinit var student: ObservableArrayMap<String, String>
    private lateinit var ob: ObservableArrayList<String>
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //setContentView(R.layout.activity_main)

        var binding: ActivityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main)
        user = PlainUser()
        binding.user = user
        user.firstName.set("陈")
        user.lastName.set("益")
        user.age.set(30)
        user.isStudent.set(true)
        user.student.put("stu", "Google")

        //user.firstName.addOnPropertyChangedCallback()

        student = ObservableArrayMap<String, String>();
        student.put("stu2", "aliyun")
        binding.student = student

        //student.addOnMapChangedCallback()

        ob = ObservableArrayList<String>();
        ob.add("baidu");
        ob.add("Inc.");
        ob.add("17");
        binding.ob = ob
    }

    fun onClickChangeFirtName2(view: View) {
        student["stu2"] = "阿里云"
        ob[1] = "百度"
    }
    fun onClickChangeFirtName(view: View) {
        user.firstName.set("我们")
    }
    fun onClickChangeLastName(view: View) {
        user.lastName.set("是哦")
    }
}
